package fw.server;

import java.io.IOException;
import java.net.*;

public class WebServer {

	public static String WEB_ROOT;
	
	private int port;
	
	public WebServer(int port){
		this.port = port;
	}
	
	public void startServer(){
		try {
			ServerSocket ss = new ServerSocket(port);
			while(true){
				Socket socket = ss.accept();
				new SocketProcessor(socket).start();
			}
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		int port = 80;
		if(args.length <2){
			System.out.println("Parameter example: 80 c:/web_root");
			return;
		}
		
		port = Integer.parseInt(args[0]);
		WebServer.WEB_ROOT = args[1];

		new WebServer(port).startServer();
	}

}
